package com.darren.archive.filter;


import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;
import java.util.Date;

/**
 *计时过滤器
 */
@Component
public class ServiceMethodFilter  implements  Filter{

    @Override
    public void init(FilterConfig filterConfig) throws ServletException{
        System.out.println("Time Filter initial");
    }

    @Override
    public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain) throws IOException,ServletException {
        System.out.println("Time Filter Start");
        //开始时间
        Long start = new Date().getTime();
        //过滤的实际业务
        chain.doFilter(request,response);
        //结束时间
        Long end = new Date().getTime();
        System.out.println("过滤用时："+(end-start));
        System.out.println("Time Filter End");
    }

    @Override
    public void destroy(){
        System.out.println("Time Filter Destroy");
    }
}


